Skip to content

feat(module): add EvaluationModuleError to public API and wrap _compute exceptions#779

Open
rityagodala wants to merge 2 commits into
huggingface:mainfrom
rityagodala:feat/evaluation-module-error-public-api
Open

feat(module): add EvaluationModuleError to public API and wrap _compute exceptions#779
rityagodala wants to merge 2 commits into
huggingface:mainfrom
rityagodala:feat/evaluation-module-error-public-api

Conversation

@rityagodala

Copy link
Copy Markdown

Summary

EvaluationModuleError did not exist in the public API, so users had no way to catch evaluate-specific errors — raw ValueError / KeyError from sklearn or numpy leaked straight to the caller.

Changes

src/evaluate/module.py

  • Introduces EvaluationModuleError(Exception) right after the logger setup
  • Wraps the self._compute(**inputs, **compute_kwargs) call in compute() so any unexpected exception is re-raised as EvaluationModuleError with a descriptive message; already-typed errors are re-raised as-is

src/evaluate/__init__.py

  • Exports EvaluationModuleError alongside EvaluationModule

Before / After

import evaluate

acc = evaluate.load("accuracy")

# Before:
# hasattr(evaluate, "EvaluationModuleError")  # False
# acc.compute(predictions=[], references=[])  # raises raw ValueError

# After:
print(hasattr(evaluate, "EvaluationModuleError"))  # True

try:
    acc.compute(predictions=[], references=[])
except evaluate.EvaluationModuleError as e:
    print(f"Caught: {e}")
# Caught: Metric computation failed for 'accuracy': ...

Fixes #758

…te errors

- Define `EvaluationModuleError` in `module.py` (subclasses Exception)
- Wrap `self._compute(**inputs)` in `compute()` so all internal
  errors (sklearn, numpy, etc.) are re-raised as `EvaluationModuleError`
  with a descriptive message; already-wrapped errors are re-raised as-is
- Export `EvaluationModuleError` from `evaluate/__init__.py`

Users can now write:
    except evaluate.EvaluationModuleError as e: ...
instead of catching broad Exception.

Fixes huggingface#758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EvaluationModuleError not exported from public API — sklearn errors leak to users

1 participant